import os

print __file__

currentDir    = os.path.split( __file__)[0]

VersionTemplate = open(os.path.join(currentDir ,"lpsolve.rc.template"), "r").read()
VersionFilePath = os.path.join(currentDir ,"lpsolve.rc")
VersionFile = open(os.path.join(currentDir ,"lpsolve.rc"), "w")

try: 
	os.remove(VersionFilePath) 
except:
	pass

	

try:
    (dummy, svnDir) = os.popen4("svnversion ../../.. ")
    svnDir = svnDir.readlines()[0]
    svnDir = svnDir.strip()

    print ' SVN number of lpsolve:        '+ svnDir
    VersionTxt = VersionTemplate.replace("@(svn_version)", svnDir)
    VersionFile.write(VersionTxt)
    VersionFile.close()
   

except:
    VersionFile.close()
    os.remove(VersionFilePath) 
    print 'Abort.... possible error in file /lps/v5520/lpsolve/lpsolve55/version_generate.py'    
